package com.zrq.secondkill.error;


import lombok.Getter;
import lombok.Setter;

public class BusinessException extends Exception implements CommonError {

    @Getter
    @Setter
    private CommonError commonError;

    @Override
    public Integer getErrCode() {
        return commonError.getErrCode();
    }

    @Override
    public String getErrMsg() {
        return commonError.getErrMsg();
    }

    public BusinessException(CommonError commonError) {
        super();
        this.commonError = commonError;
    }

    /**
     * 使用预定义的错误码,但替换错误信息
     * 减少同一类错误码的大量定义,例如各种不存在
     *
     * @param commonError
     * @param errMsg
     */
    public BusinessException(CommonError commonError, String errMsg) {
        super();
        this.commonError = commonError;
        this.commonError.setErrMsg(errMsg);
    }

    @Override
    public void setErrMsg(String errMsg) {
        commonError.setErrMsg(errMsg);
    }
}
